home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
002
/
fgrep145.arc
/
FGREP.DOC
< prev
Wrap
Text File
|
1987-05-07
|
10KB
|
231 lines
fgrep 1.45
----------
"|" denotes items that are new/changed in the current version.
Note that some previous versions were simply called "grep".
Purpose
-------
Fgrep (Fast GREP) is a small utility that can be used to find
specific strings of characters in ASCII text files. String
search capabilities are not extensive (no regular expressions),
but fgrep is small and quite fast (on a standard PC equipped
with a fairly slow fixed disk, fgrep can perform a case and
spacing insensitive search of 30 files totalling over 1/3
megabyte of text in about 22 seconds). Fgrep is intended to
replace DOS's FIND filter with something faster and more
flexible.
UNIX people: we fully realize that this isn't the grep with
which you are familiar. However, the name serves to point
people in the right direction.
Using fgrep
-----------
Fgrep's syntax is
fgrep [-cfnvwse01] target {file}
The -switches are discussed below.
| The target is the string of characters for which you are
| searching. It may need to be bracketed by a pair of
| non-alphanumeric delimiters. The target should be delimited if:
|
| -- it contains spaces or tabs
| -- it begins with a non-alphanumeric character
| -- it contains the DOS redirection characters < > |.
|
| In the last case, the string MUST be delimited by double quotes
| ("), otherwise DOS will interpret it as redirection.
|
| Examples of targets:
|
| mov
| ax
| /mov ax/ (contains a space)
| '/7' (begins with non-alphanumeric)
| "f->x" (contains ">", must use double quotes)
|
| It is always OK to delimit a string, even if delimiters are
| unnecessary.
The string may include one or more "?" wildcards. The ? will
match any single non-null character in the file. E.g., "[?i]"
will match "[si]", "[di]", etc., but not "[i]".
The list of files may include wild cards. Here are some
examples of fgrep use:
fgrep -c "include foo.c" *.c
fgrep abcd? filea.ext fileb.ext filec.ext
fgrep -1f 'call fido' a:\masm\*.asm b:*.asm
fgrep ax *.asm
If no file is specified, input will be taken from standard
input, allowing redirection and piping:
arc p somefile foo.txt | fgrep somestring
will display occurrences of "somestring" in the file archived as
foo.txt in somefile.arc.
Output
------
Fgrep's screen output looks like this:
**File <filename>
[text of lines containing string]
**File <filename>
[text of lines containing string]
All useful output is sent to the standard output device, so it
may be piped to other programs or redirected to file:
fgrep target filea | yourprog
fgrep target filea > test.txt
Error messages and the program logo will appear always appear on
the console device, and will never appear in redirected or piped
output.
Fgrep always returns an errorlevel to the operating system. It
will be one of:
0: String not found in any file
1: String found in at least one file
255: Error (file read error, or bad parameter)
Switches
--------
The -c switch makes the search case sensitive ("String" will not
match "string" or "STRING"). Normally, fgrep ignores case.
The -v switch provides a reVerse or negative search. That is,
all lines that do NOT contain the specified string are
displayed. This provides a handy way to get rid of lines
containing specified text. Suppose, for example, that you have
a file containing a list of file names, and you are interested
in all files EXCEPT those that contain a '$' in the name
(perhaps they are temporary files):
fgrep -v "$" filename
The -f switch causes the "**File" header lines to be displayed
only for those files that contain the search string.
| The -l (alpha L) switch adds line numbers to fgrep's output.
The -s switch suppresses the "**File" header lines in the
output.
The -w switch indicates that white space (blanks and tabs)
is not significant. White space in both the search string
and the input file will be ignored. If -w is specified, the
wildcard character (?) will match any nonblank character.
The -0 switch ("0" text lines) suppresses the display of lines
of text containing the specified string. fgrep will skip
immediately to the next file when the string is found.
The -1 switch ("1" text line) specifies that only the first line
containing containing the specified string in each file will be
displayed. fgrep will then skip immediately to the next file.
The -e switch specifies that ONLY an errorlevel is to be
returned. There will be no display at all. This is equivalent
to the combination -s0.
Notes
-----
1. The -f and -s switches are mutually exclusive. If both are
specified, the last one will be effective.
2. If you specify the -e switch, fgrep will stop processing as
soon as a nonzero errorlevel is determined. The -e switch is
really designed to enable other programs to determine whether or
not a specific file contains a specific string in as little time
as possible. For example, here's an algorithm that will quickly
'touch' all files that do NOT contain a specified string:
for file in (*.*) do
fgrep -e "string" file
if errorlevel < 1 then touch file
end
3. The -s switch is automatically set when input is taken from
standard input.
4. fgrep optimizes the combination -s0 (suppress headers, no
text) to a -e.
5. If you just want to know which files contain a string, use -0;
it saves time because the rest of the file (after the first hit)
is skipped. The combination -0f is particularly efficient
for this as it will simply display a list of files that contain
the string.
Version 1.45
------------
We found a few areas that could be made more efficient. This
version can be as much as 25-30% faster than version 1.40.
The -L (line numbers) option was added, and improvements made to
parameter parsing such that delimiters are not always necessary.
Copyright/License/Warranty
--------------------------
This document and the program file FGREP.EXE ("the software")
are copyrighted by the author. The copyright owner hereby
licenses you to: use the software; make as many copies of the
program and documentation as you wish; give such copies to
anyone; and distribute the software and documentation via
electronic means. There is no charge for any of the above.
However, you are specifically prohibited from charging, or
requesting donations, for any such copies, however made; and
from distributing the software and/or documentation with
commercial products without prior permission. An exception is
granted to not-for-profit user's groups, which are authorized to
charge a small fee (not to exceed $7) for materials, handling,
postage, and general overhead. NO FOR-PROFIT ORGANIZATION IS
AUTHORIZED TO CHARGE ANY AMOUNT FOR DISTRIBUTION OF COPIES OF
THE SOFTWARE OR DOCUMENTATION, OR TO INCLUDE COPIES OF THE
SOFTWARE OR DOCUMENTATION WITH SALES OF THEIR OWN PRODUCTS.
THIS INCLUDES A SPECIFIC PROHIBITION AGAINST FOR-PROFIT
ORGANIZATIONS DISTRIBUTING THE SOFTWARE, EITHER ALONE OR WITH
OTHER SOFTWARE, AND CHARGING A "HANDLING" OR "MATERIALS" FEE OR
ANY OTHER SUCH FEE FOR THE DISTRIBUTION. NO FOR-PROFIT
ORGANIZATION IS AUTHORIZED TO INCLUDE THE SOFTWARE ON ANY MEDIA
FOR WHICH MONEY IS CHARGED. PERIOD.
No copy of the software may be distributed or given away without
this document; and this notice must not be removed.
There is no warranty of any kind, and the copyright owner is not
liable for damages of any kind. By using this free software,
you agree to this.
The software and documentation are:
Copyright (C) 1985, 1986, 1987 by
Christopher J. Dunford
10057-2 Windstream Drive
Columbia, Maryland 21044
(301) 992-9371
Comments to Chris Dunford [CIS 76703,2002]. For personal use
only. Not for sale.